class Utils {
  static String camelizeKey(String key,
      [List<String> separators = const ["_", "-"]]) {
    var out = [];
    int i = 0;
    Set separatorsSet = separators.toSet();
    while (i < key.length) {
      if (separatorsSet.contains(key[i])) {
        out.add(key[i + 1].toUpperCase());
        i++;
      } else {
        out.add(key[i]);
      }
      i++;
    }
    return out.join("");
  }

  static Object camelize(Object obj) {
    if (obj == null) {
      return null;
    }
    if (obj is List) {
      if (obj.isEmpty) {
        return List();
      }
      return obj.map((item) => Utils.camelize(item)).toList();
    } else if (obj is Map) {
      Map<String, dynamic> out = {};
      for (var key in obj.keys) {
        var v = obj[key];
        out[Utils.camelizeKey(key)] = Utils.camelize(v);
      }
      return out;
    } else {
      return obj;
    }
  }
}
